package com.youngking.guns.modular.weixin;



import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;

/**
 * http://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index
 */

public class AuthUtil {
    public static JSONObject doGetJson(String url) throws IOException, JSONException {
        JSONObject jsonObject=null;
        DefaultHttpClient client=new DefaultHttpClient();
        HttpGet httpGet=new HttpGet(url);
        System.out.println(url);
        HttpResponse response=client.execute(httpGet);
        HttpEntity entity=response.getEntity();
        if(entity!=null){
            String result = EntityUtils.toString(entity, "UTF-8");
            jsonObject=  new JSONObject(result);
        }
        httpGet.releaseConnection();
        return jsonObject;
    }
}
